var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');


// 引入文件上传模块
var fileUpload = require('./routes/files_upload');

// 引入路由器模块
var searchsomething = require('./routes/indexSearch');
var svgRouter = require('./routes/svg');
var userRouter = require('./routes/user');
var indexHotelRouter = require('./routes/index_hotel');
var invRouter = require('./routes/invatation');
var slidePicRouter = require('./routes/slide_pic');
var travelMealRouter = require('./routes/travel_meal');
var vedioMakeRouter = require('./routes/vedio_make');
var searchRec = require('./routes/search_rec');

// 苏凯的路由文件引入开始
var pictureRouter = require('./routes/picture');
// 苏凯的路由文件引入结束

// 王瑞的路由文件引入开始
const indexRouter = require('./routes/hotel');
const shopRouter = require('./routes/shop');
// 王瑞的路由文件引入结束

// 雷耀的路由文件引入结束
const hotelRouter = require('./routes/leiyao');
// 雷耀的路由文件引入结束


// 袁子君引入攻略路由器模块
const strategyRouter = require('./routes/strategy');

// 贾宇引入路由
var shoppingRouter = require('./routes/shopping');




var app = express();
//cors跨域
var cors = require("cors")
app.use(cors({
  origin: ['http://localhost:8080', 'http://127.0.0.1:8080', 'http://1.hunliji.applinzi.com', 'http://hunliji.applinzi.com', 'https://hunliji.applinzi.com']
}))


// view engine setup
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

//挂载路由器
app.use('/v1/svg', svgRouter);
app.use('/v1/user', userRouter);
app.use('/v1/hotel', indexHotelRouter);
app.use('/v1/inva', invRouter);
app.use('/v1/slide', slidePicRouter);
app.use('/v1/travel', travelMealRouter);
app.use('/v1/vedio', vedioMakeRouter);
app.use('/v1/search', searchRec);
app.use('/v1/Isearch', searchsomething);
//挂载文件上传的路由
app.use('/v1/files', fileUpload)
// 苏凯的挂载开始
app.use('/v1/picture', pictureRouter);
// 苏凯的挂载结束

// 王瑞的挂载开始
app.use('/v1', indexRouter);
app.use('/v1', shopRouter);
// 王瑞的挂载结束

// 雷耀的挂载结束
app.use('/v1', hotelRouter);
// 雷耀的挂载结束


// 袁子君挂载攻略路由器
app.use('/v1/strategy', strategyRouter);

// 贾宇挂载路由
app.use('/v1/shopping', shoppingRouter);



// catch 404 and forward to error handler
app.use(function (req, res, next) {
  next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
